﻿using System.Collections.Generic;
using SomeGame.Actors.Components;

namespace SomeGame.Actors.Types {

    public class Trigger : Actor {

        public bool Enabled;
        private readonly IList<Actor> Targets = new List<Actor>();

        public Trigger(string name, Body body, bool enabled = true) 
			: base(name, body) {
            AddComponent(body);
            Enabled = enabled;
        }

        public void AddTarget(Actor target) {
            Targets.Add(target);
        }

        public void Execute() {
            /* Triggers are one-use. Can't be executed twice. */
            if (Enabled) {
                for (int i = 0; i < Targets.Count; i++) {
                    Targets[i].GetComponent<TriggerTarget>().Execute();
                }
            }
        }

    }

}